import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:juming_test/model/domain/domain_filter_condition_model.dart';

class DomainFilterConditions extends StatelessWidget {
  const DomainFilterConditions({
    super.key,
    required this.list,
    required this.onDelete,
    this.pageType = DomainConditionPageType.filter,
  });

  // 数据源
  final List<DomainFilterConditionModel> list;
  // 页面类型
  final DomainConditionPageType pageType;
  // 事件
  // 删除回调
  final Function(int index) onDelete;

  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing: 8.w,
      runSpacing: 8.h,
      children:
          list
              .map(
                (item) => Chip(
                  label: Text(item.value, style: TextStyle(fontSize: 12.sp)),
                  side: BorderSide.none,
                  backgroundColor:
                      pageType == DomainConditionPageType.filter
                          ? Colors.grey[200]
                          : Colors.white,
                  deleteIcon: Container(
                    decoration: BoxDecoration(
                      color:
                          pageType == DomainConditionPageType.filter
                              ? Colors.grey
                              : Colors.white,
                      shape: BoxShape.circle,
                    ),
                    child: Icon(
                      pageType == DomainConditionPageType.filter
                          ? Icons.remove
                          : Icons.close,
                      size: 14,
                      color:
                          pageType == DomainConditionPageType.filter
                              ? Colors.white
                              : Colors.black87,
                    ),
                  ),
                  onDeleted: () {
                    final index = list.indexOf(item);
                    if (index != -1) {
                      onDelete(index); // 删除回调
                    }
                  },
                ),
              )
              .toList(),
    );
  }
}

enum DomainConditionPageType { filter, list }
